﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LeetCodeSolutions
{
    /// <summary>
    /// 1031. 两个非重叠子数组的最大和
    /// </summary>
    class LeetCode1031: LeetCodeBase
    {
        public override void Execute()
        {
            int[] nums = new int[10] { 2, 1, 5, 6, 0, 9, 5, 0, 3, 8 };
            int firstLen = 4;
            int secondLen = 3;
            CommonFuntions.Print("Result : ", MaxSumTwoNoOverlap(nums, firstLen, secondLen).ToString());
        }

        //nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2
        //nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3
        public int MaxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen)
        {
            List<int> firstSumsList = new List<int>();
            List<int> secondSumsList = new List<int>();

            GetSumsList(nums, firstSumsList, firstLen);
            GetSumsList(nums, secondSumsList, secondLen);

            for (int i = 0; i < firstSumsList.Count; i++)
            {
                CommonFuntions.Print(firstSumsList[i]);
            }
            CommonFuntions.Print("\n");

            for (int i = 0; i < secondSumsList.Count; i++)
            {
                CommonFuntions.Print(secondSumsList[i]);
            }

            for (int i = 0; i < firstSumsList.Count; i++)
            {
                for (int j = 0; j < secondSumsList.Count; j++)
                {
                    
                }
            }

            return firstSumsList.Max() + secondSumsList.Max();
        }

        private void GetSumsList(int[] nums, List<int> sumsList, int len)
        {
            for (int i = 0; i <= nums.Length - len; i++)
            {
                int sum = 0;
                for (int j = i; j < len + i; j++)
                {
                    sum += nums[j];
                }
                sumsList.Add(sum);
            }
        }
    }
}
